{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <!-- Panel Other -->
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>订单列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="collapse" id="searchBox">
                        <div class="layui-form layui-form-item">
                            <div class="layui-input-inline">
                                <input type="text"  name="start" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm'})"  class="layui-input layer-date search" placeholder="下单开始日期" />
                            </div>
                            <div class="layui-input-inline">
                                <input type="text"  name="end" onclick="laydate({istime: true,format: 'YYYY-MM-DD hh:mm'})"  class="layui-input layer-date search" placeholder="下单结束日期" />
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="status"  lay-search="">
                                    <option  value="">不限状态</option>
                                    <option  value="1">未支付</option>
                                    <option  value="2">待收货</option>
                                    <option  value="3">待评价</option>
                                    <option  value="4">已完成</option>
                                </select>
                            </div>
                            <div class="layui-input-inline layui-form">
                                <select name="type"  lay-search="">
                                    <option  value="">不限方式</option>
                                    <option  value="1">支付宝</option>
                                    <option  value="2">微信</option>
                                </select>
                            </div>
                            <div class="layui-col-md6 layui-input-inline">
                                <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="单号/用户"/>
                            </div>
                            <div class="layui-input-inline">
                                <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                                <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
                <!--操作框开始-->
                <div class="col-sm-12">
                    <div class="input-group pull-left" >
                        <a href="javascript:;" onclick="tableReload()" class="btn btn-success" data-toggle="tooltip" title="" data-original-title="刷新表格" data-placement="auto">
                            <i class="fa fa-refresh"></i>
                        </a>
                    </div>
                    <div class="input-group pull-right" data-toggle="tooltip" title="" data-original-title="搜索">
                        <button class="btn btn-primary" data-toggle="collapse"
                                data-target="#searchBox" >
                            <i class="glyphicon glyphicon-search"></i>
                        </button>
                    </div>
                </div>
                <!--操作框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--状态模板-->
                    <script type="text/html" id="staBar">
                        {{# if(d.order_status == 1){ }}
                            <span class="layui-badge">未支付</span>
                        {{# }else if(d.order_status == 2){ }}
                            <span class="layui-badge layui-bg-orange">待收货</span>
                        {{# }else if(d.order_status == 3){ }}
                            <span class="layui-badge layui-bg-blue">待评价</span>
                        {{# }else if(d.order_status == 4){ }}
                            <span class="layui-badge layui-bg-green">已完成</span>
                        {{# } }}
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;"onclick="wk.layer_show('订单详情','{:url('orderDetail')}?id={{d.order_id}}',900)" class="btn btn-primary btn-xs m-r-xs" title="订单详情"><i class="fa fa-eye"></i></a>
                        {{# if(d.order_in_out == 2 || d.order_in_out == 4){ }}
                        <a href="javascript:;"onclick="agreeshop('{{d.order_id}}')" class="btn btn-danger btn-xs m-r-xs" title="退款"><i class="fa fa-location-arrow"></i></a>
                        {{# } }}
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("Order/index")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'order_number', width: 220, title: '订单号', align: 'center'}
                , {field: 'user_username', width: '', title: '用户', align: 'center'}
                , {field: 'order_num', width: '', title: '数量', align: 'center'}
                , {field: 'order_user_pay', width: '', title: '支付金额',  align: 'center'}
                , {field: 'order_type', width: '', title: '支付方式', align: 'center',templet:'<div>{{d.order_type == 1?"支付宝":"微信"}}</div>'}
                , {field: 'order_time', width: 180, title: '下单时间', align: 'center'}
                , {field: 'order_status',fixed: 'right', title: '状态',align: 'center', templet: '#staBar'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
        });
    });
    function agreeshop(id){
        layer.confirm('确定要退款吗？', {
            btn: ['同意','拒绝'] //按钮
        }, function(){
            shopchange(3,id)
        }, function(){
            shopchange(4,id)
        });
    }
    function shopchange(type,id){
        $.ajax({
            url: "{:url('orderBackDoByAdmin')}",
            type:'post',
            data:'type='+type+'&order_id='+id,
            dataType:'json',
            success:function(res){
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    })
                }else if(res.code == 100){
                    wk.error(res.msg,'',2);
                }
            }
        })
    }
</script>
</body>
</html>